package com.xjl.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xjl.demo.PageInfo;
import com.xjl.service.GoodsService;
import com.xjl.service.impl.GoodsServiceImpl;
@WebServlet("/showgoods")
public class ShowAllGoodsServlet extends HttpServlet {

	GoodsService gs = new GoodsServiceImpl();
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//设置请求编码格式
		req.setCharacterEncoding("utf-8");
		//设置响应编码格式
		resp.setContentType("text/html;utf-8");
		//第一次访问的验证,如果没有传递参数,设置默认值
		String pageSizeStr = req.getParameter("pageSize");
		int pageSize = 4;
		if(pageSizeStr!=null&&!pageSizeStr.equals("")){
			pageSize = Integer.parseInt(pageSizeStr);
		}
		String pageNumberStr = req.getParameter("pageNumber");
		int pageNumber = 1;
		if(pageNumberStr!=null&&!pageNumberStr.equals("")){
			pageNumber = Integer.parseInt(pageNumberStr);
		}
		PageInfo pi = gs.showPage(pageSize, pageNumber)	;	
		
		req.setAttribute("PageInfo", pi);
		req.getRequestDispatcher("qiantai/index.jsp").forward(req, resp);
		
	}

}
